<?php
date_default_timezone_set("Asia/Shanghai");
$now	=	date("H:i");
require './lib/commom.php';
$bid	=	(int)$_GET["bid"]; 
if ($bid == ""){
	header("HTTP/1.0 404 Not Found");
	exit();}
$cid	=	(int)$_GET["cid"]; 
if ($cid == "")	die("参数错误");
$bbid	=	floor($bid/1000);
$cachexmlname	=	"cached/c/xml/".$bbid."/".$bid."/".$cid.".xml";
$file="";
$file	=	cachexml($cachexmlname);
//检测缓存情况
	if($file==""){
		$path	=	"cached/c/xml/".$bbid."/".$bid."/";
		path($path);
		//缓存不存在，远程采集子程序开始
		dobook($bid,$cid);
		//远程采集子程序结束
}
		$xml = new SimplexmlElement($cachexmlname,NULL,TRUE);
		$title	=	$xml->books->title;
		$bid	=	$xml->books->bid;
		$pcid	=	$xml->books->pcid;
		$ncid	=	$xml->books->ncid;
		$content	=	$xml->books->content;
		
			if($pcid == ""){
				$preview_page_c		=	"/book/".$bid."/index.html";
			}
			else{
				$preview_page_c	=	"/book/".$bid."/".$pcid.".html";
			}
			if($ncid == ""){
				$nextpage_c		=	"/book/".$bid."/index.html";
			}
			else{
				$nextpage_c		=	"/book/".$bid."/".$ncid.".html";
			}
	$index_c		=	"/book/".$bid."/index.html";
	$tpl	=	readtpl("./tpl/reader1.html");
	$tpl	=	str_replace("<$-title-$>",$title,$tpl);
	$tpl	=	str_replace("<$-bname-$>",$bname,$tpl);
	$tpl	=	str_replace("<$-preview_page_c-$>",$preview_page_c,$tpl);
	$tpl	=	str_replace("<$-nextpage_c-$>",$nextpage_c,$tpl);
	$tpl	=	str_replace("<$-index_c-$>",$index_c,$tpl);
	$tpl	=	str_replace("<$-content-$>",$content,$tpl);
	$tpl	=	str_replace("<$-bid-$>",$bid,$tpl);
	$tpl	=	str_replace("<$-cid-$>",$cid,$tpl);
	echo $tpl;

?>
